import {TypeUtils} from "/@/utils/TypeUtils.ts";
import AppUtil from "/@/utils/app.ts";
import {defineAsyncComponent} from "vue";

export default class ComponentUtils {
    /**
     * 检查是否为数字类型（适用于字符串）
     */
    static setSelectValue(value: string | [] | object | null | undefined,split = ','): [] | string[] {
        if (value == null) {
            return []
        }
        if (TypeUtils.isArray(value)) {
            return value;
        }
        if (TypeUtils.isString(value)) {
            return value.split(split)
        }
        if (TypeUtils.isNumber(value)) {
            return [value]
        }
        return []
    }

    static async loadComponent(componentKey:string) {

        let componentMap = AppUtil.getComponentMap();
        let component = componentMap.get(componentKey);
        const a = await defineAsyncComponent(component)
        return a
    }
}
